/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tuoc;

import java.text.SimpleDateFormat;
import java.util.*;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

/**
 *
 * @author apple
 */
public class manage_controller {
    products_model productModel = new products_model();
    tables_model tablesModel = new tables_model();
    orders_model ordersModel = new orders_model();
    order_detail_model orderDetailModel = new order_detail_model();
    
    public boolean saveProduct(String productName,String productUnit,String productPrice)
    {
        Map<String,String> productData = new HashMap<String, String>();
        productData.put("name", productName);
        productData.put("unit", productUnit);
        productData.put("price", productPrice);
        return productModel.insert_data(productData);
        
    }
    
    public boolean saveTable(String tableName)
    {
        Map<String,String> tableData = new HashMap<String, String>();
        tableData.put("name", tableName);
        
        return tablesModel.insert_data(tableData);
    }
    
    public DefaultTableModel getAllOrder(TableModel model)
    {
        
        
        DefaultTableModel currentModel = (DefaultTableModel)model;
        Vector allOrders = ordersModel.get_elements();
        Iterator iter = allOrders.iterator();
        while(iter.hasNext())
        {
            orders_model currentObject = (orders_model)iter.next();
            Vector row = new Vector();
            row.add(currentObject.id);
            row.add(currentObject.get_table_name());
            row.add(currentObject.total);
            row.add(currentObject.created_date);
            currentModel.addRow(row);
        }
        return currentModel;
    }
    
    public DefaultTableModel getOrderDetail(String order_id,TableModel model)
    {
        DefaultTableModel currentModel = (DefaultTableModel)model;
        Vector allDetail = orderDetailModel.get_elements_by_order(order_id);
        Iterator iter = allDetail.iterator();
        while(iter.hasNext())
        {
            order_detail_model currentObject = (order_detail_model)iter.next();
            Vector row = new Vector();
            row.add(currentObject.id);
            row.add(currentObject.get_product_name());
            row.add(currentObject.quantity);
            row.add(currentObject.subtotal);
            currentModel.addRow(row);
            
        }
        return currentModel;
    }
}
